<? 
$msg="";
require("required/dbconnect.php"); 
require("required/function.php"); 
require("required/header.php"); 
if(isset($_POST['btnsubmit']))
{

	$oldpassword=$_POST['oldpassword'];
	$newpassword=$_POST['newpassword'];
	
	$chkoldpwd=mysql_query("select user_password from os_user where id=".$_SESSION['admin_loginid'])or die(mysql_error());
	if(mysql_result($chkoldpwd,0,"user_password")!=$oldpassword)
	{
		$msg="<font color=red>Invalid old password,please check</font>";
	}
	else
	{
		$updatepwd=mysql_query("update os_user set user_password='$newpassword' where id=".$_SESSION['admin_loginid']);
		$msg="<font color=green>Password changed successfully</font>";
	}
}



?>
<script language="javascript">
	function formvalidate(frm)
		{
		if(document.frm.oldpassword.value=="")
		{
			alert("Please enter old password");
			document.frm.oldpassword.focus();
			return false;
		}
		if(document.frm.newpassword.value=="")
		{
			alert("Please enter new password");
			document.frm.newpassword.focus();
			return false;
		}
		if(document.frm.cnewpassword.value=="")
		{
			alert("Please confirm new password");
			document.frm.cnewpassword.focus();
			return false;
		}
		if(document.frm.cnewpassword.value!=document.frm.newpassword.value)
		{
			alert("Password not match,please check again");
			document.frm.cnewpassword.focus();
			return false;
		}
		return true;
	}
</script>
				<table width="100%"  cellpadding="0" cellspacing="5" height="300">
					
					<td width="84%" valign="top" >
						<table width="100%">
							<tr>
							<td colspan="5" class="title">Change Password</td>
							</tr>
							<tr>
								<td align="left">
									<table width="500">
										<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm" onSubmit="return formvalidate(this)">
											<td colspan="3"><?= $msg ?></Td>
										</tr>
										<tr>
											<td width="20%">Old Password</td><td width="1%">:</td><Td width="79%" align="left"><input type="password" name="oldpassword" size="15" maxlength="20"></Td>
										</tr>
										<tr>
											<td>New Password</td><td>:</td><Td align="left"><input type="password" name="newpassword" size="15" maxlength="20"></Td>
										</tr>
										<tr>
											<td>Confirm Password</td><td>:</td><Td align="left"><input type="password" name="cnewpassword" size="15" maxlength="20"></Td>
										</tr>
										
										<tr>
											<Td colspan="3"><input type="submit" class="button" value="Submit" name="btnsubmit"></Td>
										</tr>
										</form>
								  </table>
								</td>
							</tr>
						</table>
		
					</td>
					
				 
				</table>
<? require("required/footer.php"); ?>